package NIO;

import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

public class SocketAccept {
    public static void main(String[] args)throws Exception {
        Socket socket = new Socket("localhost" , 1234);
        byte[] buffer = new byte[1024];
        int len = socket.getInputStream().read(buffer);
        System.out.println(new String(buffer ,0 , len , "utf-8"));

        SocketChannel socketChannel = SocketChannel.open( );
        socketChannel.connect (new InetSocketAddress("localhost", 1234));
        ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
        socketChannel.read(byteBuffer);
        System.out.println(new String(byteBuffer.array()));

    }
}
